package y;

import java.util.Scanner;
import java.util.Arrays;
import java.util.EmptyStackException;

public class Main2 {

	public static void main(String[] args) throws FullStackException {
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		IntegerStack stack=new ArrayIntegerStack(n);
		int m= sc.nextInt();
		for(int i=0;i<m;i++)
		{
			System.out.println(stack.push(sc.nextInt()));
		}
		System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
		System.out.println(stack.toString());
		int a=sc.nextInt();
		for(int i=0;i<a;i++)
		{
			System.out.println(stack.pop());
		}
		System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
		System.out.println(stack.toString());
	}

}
interface IntegerStack {
	public Integer push (Integer item) throws FullStackException;
	public Integer pop();
	public Integer peek();
	public boolean empty();
	public int size();

}
class ArrayIntegerStack implements IntegerStack {
	private Integer arr[];
	private int top=0;

	public Integer[] getArr() {
		return arr;
	}
	
	public ArrayIntegerStack(int n) {
		arr= new Integer[n];
	}

	@Override
	public String toString() {
		return Arrays.toString(arr);
	}

	@Override
	public Integer push(Integer item) throws FullStackException{
		if (item==null)
			return null;
		if(top== arr.length){
			FullStackException e= new FullStackException() ;
		    throw e;
		}
		arr[top++] = item;
		return item;
	}

	@Override
	public Integer pop() {
		// TODO Auto-generated method stub
		if(top==0){
			EmptyStackException e = new EmptyStackException();
		    throw e;
		}
		return arr[--top];
	}

	@Override
	public Integer peek() {
		// TODO Auto-generated method stub
		if(top==0){
			EmptyStackException e = new EmptyStackException();
		    throw e;
		}
	    return arr[top-1];
	}

	@Override
	public boolean empty() {
		// TODO Auto-generated method stub
		if(top==0)
			return true;
		return false;
	}

	@Override
	public int size() {
		// TODO Auto-generated method stub
		return top;
	}
    
}
@SuppressWarnings("serial")
class FullStackException extends Exception{
	public FullStackException() {
		// TODO Auto-generated constructor stub
	}
}